<?php

/**
 * This is the model class for table "persetujuan_surat_keluar".
 *
 * The followings are the available columns in table 'persetujuan_surat_keluar':
 * @property string $id_persetujuan_surat_keluar
 * @property string $id_surat_keluar
 * @property integer $sort
 * @property string $id_pegawai
 * @property string $waktu_persetujuan
 * @property integer $setuju
 * @property string $alasan_penolakan
 * @property boolean $visible
 */
class PersetujuanSuratKeluar extends CActiveRecord
{
        public $SuratKeluarNoSurat_search;
        public $SuratKeluarJudulSurat_search;
        public $PegawaiNama_search;
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PersetujuanSuratKeluar the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'persetujuan_surat_keluar';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_surat_keluar, sort, id_pegawai', 'required'),
			array('sort,  setuju', 'numerical', 'integerOnly'=>true),
			array('id_surat_keluar, id_pegawai', 'length', 'max'=>20),
			array('waktu_persetujuan, alasan_penolakan', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array(
                            'id_persetujuan_surat_keluar, id_surat_keluar, sort, id_pegawai, 
                            status, waktu_persetujuan, setuju, alasan_penolakan,
                            SuratKeluarNoSurat_search, SuratKeluarJudulSurat_search, ', 
                            'safe', 
                            'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
                    'Pegawai'=>array(self::BELONGS_TO, 'Pegawai', 'id_pegawai'),
                    'SuratKeluar'=>array(self::BELONGS_TO, 'SuratKeluar', 'id_surat_keluar'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_persetujuan_surat_keluar' => 'Id Persetujuan Surat Keluar',
			'id_surat_keluar' => 'Id Surat Keluar',
			'sort' => 'sort',
			'id_pegawai' => 'Id Pegawai',
			'waktu_persetujuan' => 'Waktu Persetujuan',
			'setuju' => 'Setuju',
			'alasan_penolakan' => 'Alasan Penolakan',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_persetujuan_surat_keluar',$this->id_persetujuan_surat_keluar,true);
		$criteria->compare('id_surat_keluar',$this->id_surat_keluar,true);
		$criteria->compare('sort',$this->sort);
		$criteria->compare('t.id_pegawai', Yii::app()->user->id,   false);
		$criteria->compare('t.visible', 1,   false);
		$criteria->compare('waktu_persetujuan',$this->waktu_persetujuan,true);
		$criteria->compare('setuju',$this->setuju);
		$criteria->compare('alasan_penolakan', $this->alasan_penolakan,true);
                $criteria->compare('SuratKeluar.no_surat', $this->SuratKeluarNoSurat_search, true);
                $criteria->compare('SuratKeluar.Pegawai.nama', $this->PegawaiNama_search, true);
                
                $criteria->with = array('Pegawai', 'SuratKeluar');
                
                $criteria->order = 'id_persetujuan_surat_keluar DESC';
                
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}